/*
 *    Copyright © OpenAtom Foundation.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.inspur.edp.bff.spi.defaultvalue;

import com.inspur.edp.bef.api.lcp.ILcpFactory;
import com.inspur.edp.bef.api.lcp.IStandardLcp;
import com.inspur.edp.bef.api.parameter.retrieve.RespectiveRetrieveResult;
import com.inspur.edp.bef.api.parameter.retrieve.RetrieveParam;
import com.inspur.edp.bef.spi.entity.builtinimpls.BefEntityResInfoImpl;
import com.inspur.edp.bef.spi.entity.builtinimpls.BefPropertyInfo;
import com.inspur.edp.bff.api.exception.BffFrameworkException;
import com.inspur.edp.bff.api.exception.ErrorCodes;
import com.inspur.edp.bff.api.manager.IFSManager;
import com.inspur.edp.bff.api.manager.IFSManagerContext;
import com.inspur.edp.bff.entity.defaultvalue.VoDefaultValue;
import com.inspur.edp.bff.spi.builtin.BffEntityResInfoImpl;
import com.inspur.edp.bff.spi.builtin.BffPropertyInfo;
import com.inspur.edp.cef.entity.accessor.base.AccessorBase;
import com.inspur.edp.cef.entity.entity.AssoInfoBase;
import com.inspur.edp.cef.entity.entity.IEntityData;
import com.inspur.edp.cef.entity.entity.IValuesContainer;
import com.inspur.edp.cef.spi.entity.AssociationInfo;
import com.inspur.edp.cef.spi.entity.info.propertyinfo.AssocationPropertyInfo;
import com.inspur.edp.cef.spi.entity.info.propertyinfo.DataTypePropertyInfo;
import com.inspur.edp.cef.spi.entity.info.propertyinfo.EnumPropertyInfo;
import com.inspur.edp.cef.spi.entity.info.propertyinfo.ObjectType;
import com.inspur.edp.cef.spi.entity.info.propertyinfo.RefDataTypePropertyInfo;
import com.inspur.edp.cef.spi.entity.resourceInfo.ModelResInfo;
import com.inspur.edp.udt.entity.IUdtData;
import io.iec.edp.caf.commons.utils.SpringBeanUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DefaultValueUtil {

    public static Map<String, Object> transVoDefaultValueToBe(IFSManagerContext context, VoDefaultValue voDefaultValue,
                                                              ArrayList<String> nodeCodes) {
        Map<String, Object> beDefaultValue = new HashMap<>();
        Map<String, Object> voDefalutValueMap = voDefaultValue.getDefaultValue();
        //获取vo上的资源info
        BffEntityResInfoImpl voResInfo = getBffEntityResInfo(context, nodeCodes);
        //获取be上的资源info
        BefEntityResInfoImpl beResInfo = getBefEntityResInfo(context, nodeCodes);

        //遍历vo上的默认值
        for (Map.Entry<String, Object> item : voDefalutValueMap.entrySet()) {
            //获取vo字段vo上的PropertyInfo信息
            BffPropertyInfo bffPropertyInfo = (BffPropertyInfo) voResInfo.getEntityTypeInfo().getPropertyInfos().get(item.getKey().toString());
            //获取vo字段对应的be字段LabelId
            String beLabelId = bffPropertyInfo.getBeLabelId();
            //获取字段的对应的be上的PropertyInfo信息
            DataTypePropertyInfo befPropertyInfo = (beResInfo.getEntityTypeInfo().getPropertyInfos().get(beLabelId));
            //获取字段对象类型，分基本，枚举，关联，udt 动态属性
            ObjectType objectType = bffPropertyInfo.getObjectType();
            switch (objectType) {
                case Normal:
                    beDefaultValue.put(beLabelId, item.getValue());
                    break;
                case UDT:
                    beDefaultValue.put(beLabelId, ((IUdtData) item.getValue()).copySelf());
                    break;
                case Enum:
                    Class enumType = ((EnumPropertyInfo) befPropertyInfo.getObjectInfo()).getEnumType();
                    if (enumType == null) {
                        beDefaultValue.put(beLabelId, item.getValue() == null ? null : item.getValue().toString());
                    } else {
                        beDefaultValue.put(beLabelId, item.getValue() == null ? null : Enum.valueOf(enumType, item.getValue().toString()));
                    }
                    break;
                case Association:
                    //创建一个子对象data,
                    IEntityData data;
                    if (nodeCodes == null)
                        data = context.getLcp().createData("");
                    else
                        data = context.getLcp().createChildData(nodeCodes.get(nodeCodes.size() - 1), "");
                    //创建一个关联的实例
                    AssoInfoBase assoInstance = (AssoInfoBase) ((AccessorBase) data).createValue(beLabelId);
                    assoInstance.setValue(beLabelId, ((AssoInfoBase) item.getValue()).getValue(item.getKey()));
                    //获取关联的默认值
                    getAssoValueByDataTypePropInfo(item.getValue(), befPropertyInfo, beLabelId, bffPropertyInfo, assoInstance, beDefaultValue);
                    break;
                case DynamicProp:
                    throw new BffFrameworkException(ErrorCodes.BFF_FRAMEWORK_2011);
                default:
                    throw new BffFrameworkException(ErrorCodes.BFF_FRAMEWORK_2012, item.getKey());
            }
        }
        return beDefaultValue;
    }

    //运行时定制批量新增子表时，防止每次重新创建lcp,将lcp参数传进来使用
    public static Map<String, Object> transVoDefaultValueToBe(IStandardLcp lcp, IFSManagerContext context, VoDefaultValue voDefaultValue,
                                                              ArrayList<String> nodeCodes) {
        Map<String, Object> beDefaultValue = new HashMap<>();
        Map<String, Object> voDefalutValueMap = voDefaultValue.getDefaultValue();
        //获取vo上的资源info
        BffEntityResInfoImpl voResInfo = getBffEntityResInfo(context, nodeCodes);
        //获取be上的资源info
        BefEntityResInfoImpl beResInfo = getBefEntityResInfo(lcp, context, nodeCodes);

        //遍历vo上的默认值
        for (Map.Entry<String, Object> item : voDefalutValueMap.entrySet()) {
            //获取vo字段vo上的PropertyInfo信息
            BffPropertyInfo bffPropertyInfo = (BffPropertyInfo) voResInfo.getEntityTypeInfo().getPropertyInfos().get(item.getKey().toString());
            //获取vo字段对应的be字段LabelId
            String beLabelId = bffPropertyInfo.getBeLabelId();
            //获取字段的对应的be上的PropertyInfo信息
            DataTypePropertyInfo befPropertyInfo = (beResInfo.getEntityTypeInfo().getPropertyInfos().get(beLabelId));
            //获取字段对象类型，分基本，枚举，关联，udt 动态属性
            ObjectType objectType = bffPropertyInfo.getObjectType();
            switch (objectType) {
                case Normal:
                    beDefaultValue.put(beLabelId, item.getValue());
                    break;
                case UDT:
                    beDefaultValue.put(beLabelId, ((IUdtData) item.getValue()).copySelf());
                    break;
                case Enum:
                    Class enumType = ((EnumPropertyInfo) befPropertyInfo.getObjectInfo()).getEnumType();
                    if (enumType == null) {
                        beDefaultValue.put(beLabelId, item.getValue() == null ? null : item.getValue().toString());
                    } else {
                        beDefaultValue.put(beLabelId, item.getValue() == null ? null : Enum.valueOf(enumType, item.getValue().toString()));
                    }
                    break;
                case Association:
                    //创建一个子对象data,
                    IEntityData data;
                    if (nodeCodes == null)
                        data = lcp.createData("");
                    else
                        data = lcp.createChildData(nodeCodes.get(nodeCodes.size() - 1), "");
                    //创建一个关联的实例
                    AssoInfoBase assoInstance = (AssoInfoBase) ((AccessorBase) data).createValue(beLabelId);
                    assoInstance.setValue(beLabelId, ((AssoInfoBase) item.getValue()).getValue(item.getKey()));
                    //获取关联的默认值
                    getAssoValueByDataTypePropInfo(item.getValue(), befPropertyInfo, beLabelId, bffPropertyInfo, assoInstance, beDefaultValue);
                    break;
                case DynamicProp:
                    throw new BffFrameworkException(ErrorCodes.BFF_FRAMEWORK_2011);
                default:
                    throw new BffFrameworkException(ErrorCodes.BFF_FRAMEWORK_2012, item.getKey());
            }
        }
        return beDefaultValue;
    }

    private static BffEntityResInfoImpl getBffEntityResInfo(IFSManagerContext context, ArrayList<String> nodeCodes) {
        ModelResInfo modelResInfo = context.getBffManager().getModelInfo();
        BffEntityResInfoImpl voResInfo;
        if (nodeCodes == null)
            voResInfo = (BffEntityResInfoImpl) modelResInfo.getCustomResource(modelResInfo.getRootNodeCode());
        else
            voResInfo = (BffEntityResInfoImpl) context.getBffManager().getModelInfo().getCustomResource(nodeCodes.get(nodeCodes.size() - 1));
        return voResInfo;
    }

    private static BefEntityResInfoImpl getBefEntityResInfo(IFSManagerContext context, List<String> nodeCodes) {
        ModelResInfo modelResInfo = context.getLcp().getModelInfo();
        BefEntityResInfoImpl beResInfo;
        if (nodeCodes == null) {
            beResInfo = (BefEntityResInfoImpl) modelResInfo.getCustomResource(modelResInfo.getRootNodeCode());
        } else
            beResInfo = (BefEntityResInfoImpl) context.getLcp().getModelInfo().getCustomResource(nodeCodes.get(nodeCodes.size() - 1));
        return beResInfo;
    }

    private static BefEntityResInfoImpl getBefEntityResInfo(IStandardLcp lcp, IFSManagerContext context, List<String> nodeCodes) {
        ModelResInfo modelResInfo = lcp.getModelInfo();
        BefEntityResInfoImpl beResInfo;
        if (nodeCodes == null) {
            beResInfo = (BefEntityResInfoImpl) modelResInfo.getCustomResource(modelResInfo.getRootNodeCode());
        } else
            beResInfo = (BefEntityResInfoImpl) lcp.getModelInfo().getCustomResource(nodeCodes.get(nodeCodes.size() - 1));
        return beResInfo;
    }

    public static void getAssoValueByDataTypePropInfo(Object assoValue, DataTypePropertyInfo befPropertyInfo, String beLabelId, BffPropertyInfo bffPropertyInfo, AssoInfoBase assoInstance, Map<String, Object> beDefaultValue) {
        // vo上的关联的字段集合
        Map<String, DataTypePropertyInfo> map = ((AssocationPropertyInfo) bffPropertyInfo.getObjectInfo()).getAssociationInfo().getRefPropInfos();
        for (Map.Entry<String, DataTypePropertyInfo> item : map.entrySet()) {

            //todo 临时处理，关联带出字段，解析型objectInfo不是BffPropertyInfo类型，考虑到带出字段labelId不会变，临时如下处理
            DataTypePropertyInfo objectInfo = item.getValue();
            String beId = objectInfo.getPropertyName();
//      //获取当前关联字段带出字段的BffPropertyInfo信息
//      BffPropertyInfo objectInfo = (BffPropertyInfo) item.getValue();
//      //获取带出字段对应的beLabelId
//      String beId = objectInfo.getBeLabelId();


            //根据belabelId获取BefPropertyInfo
            DataTypePropertyInfo befPropertyInfo1 = ((AssocationPropertyInfo) befPropertyInfo.getObjectInfo()).getAssociationInfo().getRefPropInfos().get(beId);
            //获取带出字段的类型基本 关联 udt 枚举 动态？？？？？
            ObjectType objectType = objectInfo.getObjectType();
            switch (objectType) {
                case Normal:
                    //给be上的关联普通字段赋值
                    assoInstance
                            .setValue(beId, ((AssoInfoBase) assoValue).getValue(item.getKey()));
                    break;
                case UDT:
                    break;
                case Enum:
                    //给枚举字段赋值
                    if (((AssoInfoBase) assoValue).getValue(item.getKey()) == null) {
                        assoInstance.setValue(beId, null);
                    } else {
                        Class enumType = ((EnumPropertyInfo) (befPropertyInfo1.getObjectInfo()))
                                .getEnumType();
                        if (enumType == null) {
                            assoInstance.setValue(beId,
                                    ((AssoInfoBase) assoValue).getValue(item.getKey()).toString());
                        } else {
                            assoInstance.setValue(beId, Enum.valueOf(enumType,
                                    ((AssoInfoBase) assoValue).getValue(item.getKey()).toString()));
                        }
                    }
                    break;
                case Association:
                    assoInstance.setValue(beId, ((AssoInfoBase) assoValue).getValue(item.getKey()));
                    break;
                case DynamicProp:
                    throw new BffFrameworkException(ErrorCodes.BFF_FRAMEWORK_2011);
                default:
                    throw new BffFrameworkException(ErrorCodes.BFF_FRAMEWORK_2012, item.getKey());
            }

        }
        beDefaultValue.put(beLabelId, assoInstance);
    }

    public static void getAssoValue(Object assoValue, BefPropertyInfo befPropertyInfo, String beLabelId, BffPropertyInfo bffPropertyInfo, AssoInfoBase assoInstance, Map<String, Object> beDefaultValue) {
        getAssoValueByDataTypePropInfo(assoValue, befPropertyInfo, beLabelId, bffPropertyInfo, assoInstance, beDefaultValue);
    }

    public static IStandardLcp getAssoLcp(String configId) {
        IStandardLcp lcp = SpringBeanUtils.getBean(ILcpFactory.class).createLcp(configId);
        return lcp;
    }

    public static IEntityData getAssoData(String dataId, IStandardLcp lcp) {
        RetrieveParam param = new RetrieveParam();
        param.setNeedLock(false);
        RespectiveRetrieveResult data = lcp.retrieve(dataId, param);
        if (data == null) {
            throw new BffFrameworkException(ErrorCodes.BFF_FRAMEWORK_2013, dataId);
        }
        return data.getData();
    }

    public static void dealBasicTypeDefaultValue(BffPropertyInfo propertyInfo, String beLabelId, Map<String, Object> values) {
        if (propertyInfo.getDefaultValue() == null || propertyInfo.getDefaultValue().getRealValue() == null)
            return;
        values.put(beLabelId, propertyInfo.getDefaultValue().getRealValue());
    }

    public static void dealEnumDefaultValue(BffPropertyInfo bffPropertyInfo, BefPropertyInfo befPropertyInfo, String beLabelId, Map<String, Object> values) {
        if (bffPropertyInfo.getDefaultValue() == null || bffPropertyInfo.getDefaultValue().getRealValue() == null)
            return;
        Object value = bffPropertyInfo.getDefaultValue().getRealValue();
        Class enumType = ((EnumPropertyInfo) befPropertyInfo.getObjectInfo()).getEnumType();
        if (enumType == null) {
            values.put(beLabelId, value == null ? null : value.toString());
        } else {
            values.put(beLabelId, value == null ? null : Enum.valueOf(enumType, value.toString()));
        }
    }

    public static void dealAssoDefaultValue(IStandardLcp lcp, BffPropertyInfo bffPropertyInfo, BefPropertyInfo befPropertyInfo, String beLabelId, Map<String, Object> values,
                                            List<String> nodeCodes) {
        if (bffPropertyInfo.getDefaultValue() == null || bffPropertyInfo.getDefaultValue().getRealValue() == null)
            return;
        Object value = bffPropertyInfo.getDefaultValue().getRealValue();
        IEntityData data;
        if (nodeCodes == null)
            data = lcp.createData("");
        else
            data = lcp.createChildData(nodeCodes.get(nodeCodes.size() - 1), "");
        if (!(bffPropertyInfo.getObjectInfo() instanceof AssocationPropertyInfo)) {
            String[] messageParams = new String[]{(String) bffPropertyInfo.getObjectInfo(), bffPropertyInfo.getPropertyName()};
            throw new BffFrameworkException(ErrorCodes.BFF_FRAMEWORK_2014, messageParams);
        }
        AssociationInfo info = ((AssocationPropertyInfo) bffPropertyInfo.getObjectInfo()).getAssociationInfo();
        String configId = info.getConfig();
        IStandardLcp assoLcp = getAssoLcp(configId);
        IEntityData assoData = getAssoData(value.toString(), assoLcp);
        if (assoData == null) {
            String propertyName = bffPropertyInfo.getPropertyName();
            throw new BffFrameworkException(ErrorCodes.BFF_FRAMEWORK_2015, propertyName);
        }
        IValuesContainer assoInstance = (IValuesContainer) ((AccessorBase) data).createValue(beLabelId);
        assoInstance.setValue(beLabelId, value);
        dealAssoValueByAssociatedData(assoData, befPropertyInfo, beLabelId, bffPropertyInfo, assoInstance, values);
    }

    public static void dealAssoValueByAssociatedData(IEntityData data, BefPropertyInfo befPropertyInfo, String beLabelId, BffPropertyInfo bffPropertyInfo, IValuesContainer assoInstance, Map<String, Object> values) {
        Map<String, DataTypePropertyInfo> map = ((AssocationPropertyInfo) befPropertyInfo.getObjectInfo()).getAssociationInfo().getRefPropInfos();
        if (map == null || map.size() == 0)
            return;
        for (Map.Entry<String, DataTypePropertyInfo> item : map.entrySet()) {
            DataTypePropertyInfo objectInfo = item.getValue();
            if (!(objectInfo instanceof RefDataTypePropertyInfo))
                continue;
            String beId = objectInfo.getPropertyName();
            String refPropName = ((RefDataTypePropertyInfo) objectInfo).getRefPropertyName();
            DataTypePropertyInfo befPropertyInfo1 = ((AssocationPropertyInfo) befPropertyInfo.getObjectInfo()).getAssociationInfo().getRefPropInfos().get(beId);
            ObjectType objectType = objectInfo.getObjectType();
            switch (objectType) {
                case Normal:
                    assoInstance
                            .setValue(beId, data.getValue(refPropName));
                    break;
                case UDT:
                    throw new BffFrameworkException(ErrorCodes.BFF_FRAMEWORK_2016, beId);
                case Enum:
                    if (data.getValue(refPropName) == null) {
                        assoInstance.setValue(beId, null);
                    } else {
                        Class enumType = ((EnumPropertyInfo) (befPropertyInfo1.getObjectInfo()))
                                .getEnumType();
                        if (enumType == null) {
                            assoInstance.setValue(beId,
                                    data.getValue(refPropName).toString());
                        } else {
                            assoInstance.setValue(beId, Enum.valueOf(enumType,
                                    data.getValue(refPropName).toString()));
                        }
                    }
                    break;
                case Association:
                    assoInstance.setValue(beId, data.getValue(refPropName));
                    break;
                case DynamicProp:
                    throw new BffFrameworkException(ErrorCodes.BFF_FRAMEWORK_2017, beId);
                default:
                    String[] messageParams = new String[]{objectType.toString(), beId};
                    throw new BffFrameworkException(ErrorCodes.BFF_FRAMEWORK_2018, messageParams);
            }

        }
        values.put(beLabelId, assoInstance);
    }

    public static void dealDefaultValue(IFSManager manager, IStandardLcp lcp, DataTypePropertyInfo propertyInfo, List<String> nodeCodes, Map<String, Object> values) {
        BffPropertyInfo bffPropertyInfo = (BffPropertyInfo) propertyInfo;
        String beLabelId = bffPropertyInfo.getBeLabelId();
        BefEntityResInfoImpl beResInfo = getBefEntityResInfo(lcp, manager.getBffContext(), nodeCodes);
        DataTypePropertyInfo befPropertyInfo = (beResInfo.getEntityTypeInfo().getPropertyInfos().get(beLabelId));
        ObjectType objectType = bffPropertyInfo.getObjectType();
        switch (objectType) {
            case Normal:
                dealBasicTypeDefaultValue(bffPropertyInfo, beLabelId, values);
                break;
            case UDT:
                throw new BffFrameworkException(ErrorCodes.BFF_FRAMEWORK_2016, propertyInfo.getPropertyName());
            case Enum:
                dealEnumDefaultValue(bffPropertyInfo, (BefPropertyInfo) befPropertyInfo, beLabelId, values);
                break;
            case Association:
                dealAssoDefaultValue(lcp, bffPropertyInfo, (BefPropertyInfo) befPropertyInfo, beLabelId, values, nodeCodes);
                break;
            case DynamicProp:
                throw new BffFrameworkException(ErrorCodes.BFF_FRAMEWORK_2017, propertyInfo.getPropertyName());
            default:
                String[] messageParams = new String[]{objectType.toString(), propertyInfo.getPropertyName()};
                throw new BffFrameworkException(ErrorCodes.BFF_FRAMEWORK_2018, messageParams);

        }
    }

    public static void dealExtendValue(IFSManager manager, DataTypePropertyInfo propertyInfo, ArrayList<String> nodeCodes, Map<String, Object> values) {
        BffPropertyInfo bffPropertyInfo = (BffPropertyInfo) propertyInfo;
        String propName = bffPropertyInfo.getPropertyName();
        ObjectType objectType = bffPropertyInfo.getObjectType();
        switch (objectType) {
            case Normal:
            case Enum:
                dealBasicTypeDefaultValue(bffPropertyInfo, propName, values);
                break;
            case UDT:
                throw new BffFrameworkException(ErrorCodes.BFF_FRAMEWORK_2016, propertyInfo.getPropertyName());
            case Association:
                dealExtendAssoValue(manager, bffPropertyInfo, propName, values, nodeCodes);
                break;
            case DynamicProp:
                throw new BffFrameworkException(ErrorCodes.BFF_FRAMEWORK_2017, propertyInfo.getPropertyName());
            default:
                String[] messageParams = new String[]{objectType.toString(), propertyInfo.getPropertyName()};
                throw new BffFrameworkException(ErrorCodes.BFF_FRAMEWORK_2018, messageParams);
        }
    }

    public static void dealExtendAssoValue(IFSManager manager, BffPropertyInfo bffPropertyInfo, String beLabelId, Map<String, Object> values, ArrayList<String> nodeCodes) {
        if (bffPropertyInfo.getDefaultValue() == null || bffPropertyInfo.getDefaultValue().getRealValue() == null)
            return;
        Object value = bffPropertyInfo.getDefaultValue().getRealValue();
        IEntityData data;
        if (nodeCodes == null)
            data = manager.createData("");
        else
            data = manager.createChildData(nodeCodes.get(nodeCodes.size() - 1), "");

        if (!(bffPropertyInfo.getObjectInfo() instanceof AssocationPropertyInfo)) {
            String[] messageParams = new String[]{(String) bffPropertyInfo.getObjectInfo(), bffPropertyInfo.getPropertyName()};
            throw new BffFrameworkException(ErrorCodes.BFF_FRAMEWORK_2014, messageParams);
        }
        AssociationInfo info = ((AssocationPropertyInfo) bffPropertyInfo.getObjectInfo()).getAssociationInfo();
        String configId = info.getConfig();
        IStandardLcp assoLcp = getAssoLcp(configId);
        IEntityData assoData = getAssoData(value.toString(), assoLcp);
        if (assoData == null) {
            String propertyName = bffPropertyInfo.getPropertyName();
            throw new BffFrameworkException(ErrorCodes.BFF_FRAMEWORK_2019, propertyName);
        }
        AssoInfoBase assoInstance = (AssoInfoBase) ((AccessorBase) data).createValue(beLabelId);
        assoInstance.setValue(beLabelId, value);
        dealEntendAssoValueByAssoData(assoData, beLabelId, bffPropertyInfo, assoInstance, values);
    }

    public static void dealEntendAssoValueByAssoData(IEntityData data, String beLabelId, BffPropertyInfo bffPropertyInfo, AssoInfoBase assoInstance, Map<String, Object> values) {
        Map<String, DataTypePropertyInfo> map = ((AssocationPropertyInfo) bffPropertyInfo.getObjectInfo()).getAssociationInfo().getRefPropInfos();
        if (map == null || map.size() == 0)
            return;
        for (Map.Entry<String, DataTypePropertyInfo> item : map.entrySet()) {
            DataTypePropertyInfo objectInfo = item.getValue();
            if (!(objectInfo instanceof RefDataTypePropertyInfo))
                continue;
            String beId = objectInfo.getPropertyName();
            String refPropName = ((RefDataTypePropertyInfo) objectInfo).getRefPropertyName();
            ObjectType objectType = objectInfo.getObjectType();
            switch (objectType) {
                case Normal:
                    assoInstance.setValue(beId, data.getValue(refPropName));
                    break;
                case UDT:
                    throw new BffFrameworkException(ErrorCodes.BFF_FRAMEWORK_2016, beId);
                case Enum:
                    if (data.getValue(refPropName) == null) {
                        assoInstance.setValue(beId, null);
                    } else {
                        assoInstance.setValue(beId, data.getValue(refPropName).toString());
                    }
                    break;
                case Association:
                    assoInstance.setValue(beId, data.getValue(refPropName));
                    break;
                case DynamicProp:
                    throw new BffFrameworkException(ErrorCodes.BFF_FRAMEWORK_2017, beId);
                default:
                    String[] messageParams = new String[]{objectType.toString(), beId};
                    throw new BffFrameworkException(ErrorCodes.BFF_FRAMEWORK_2018, messageParams);
            }
        }
        values.put(beLabelId, assoInstance);
    }


}
